package com.study.cloud.custom.registerinterface;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyFactoryBean implements FactoryBean<IHelloService> {
    @Override
    public IHelloService getObject() {

        IHelloService iHelloService =
                (IHelloService) Proxy.newProxyInstance(IHelloService.class.getClassLoader(), new Class[]{IHelloService.class}, new InvocationHandler() {
                   @Override
                   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                       System.out.println("hello world");
                       return "hello world";
                   }
               });

        return iHelloService;
    }

    @Override
    public Class<?> getObjectType() {
        return IHelloService.class;
    }
}
